<script>
$(document).ready(function (){
$("#approve").click(function(){

	var userdata = new Array();
	$("#tbl_user tr td").find("input:checked").each(function(e){
			userdata[e] = $(this).val();
		});
	
		if (userdata.length <=0){
				$("#msgbox").empty().html("no row selected");
				$("#msgbox").dialog({
					modal:true,
					title:"Error",
					width:350,
					height: 200,
					show: "fade",
					hide: "fade",
					buttons: {
						OK: function() {
							$( this ).dialog( "close" );
						}

					},
				});
				
				

		}
		else if(userdata.length >=1){
		var app ="approve"
		$("#msgbox").empty().html("approve?");
			$("#msgbox").dialog({
				modal:true,
				width:350,
				height: 200,
				show:"fade",
				hide: "fade",
				buttons: {
					OK: function() {
						$( this ).dialog( "close" );
						approve(userdata,app);
					},
					CANCEL: function() {
						$( this ).dialog( "close" );
					}
				},

			});
			

		}

});//end of approve.click()

	$("#disapprove").click(function(){

	var userdata = new Array();
	$("#tbl_user tr td").find("input:checked").each(function(e){
			userdata[e] = $(this).val();
		});
	
		if (userdata.length <=0){
				$("#msgbox").empty().html("no row selected");
				$("#msgbox").dialog({
					modal:true,
					title:"Error",
					width:350,
					height: 200,
					show: "fade",
					hide: "fade",
					buttons: {
						OK: function() {
							$( this ).dialog( "close" );
						}

					},
				});
				
				

		}
		else if(userdata.length >=1){
		var disap = "disapprove";
		$("#msgbox").empty().html("Disapprove?");
			$("#msgbox").dialog({
				modal:true,
				width:350,
				height: 200,
				show:"fade",
				hide: "fade",
				buttons: {
					OK: function() {
						$(this).dialog( "close" );
						approve(userdata, disap);
					},
					CANCEL: function() {
						$( this ).dialog( "close" );
					}
				},

			});
			

		}

});//end of approve.click()

});


/*blocking user*/
function approve(userdata,app){
	if(app =="approve"){
		$.ajax({
			url:"admin/approveuser.php?userid="+userdata+"&approve="+app,
			success:function(data){
			
			
				if(data){
					//$("msgbox").empty().html("");
					$("#msgbox").html("Sucessfully approved");
						$("#msgbox").dialog({
							modal:true,
							title:"",
							width:350,
							height: 200,
							show: "fade",
							hide: "fade",
							buttons: {
								OK: function() {
									$( "#msgbox" ).dialog( "close" );
									$("#userload").html(loader).load("admin/user.php");
								}

							},
						});
				}
				else{
					$("msgbox").empty().html("something went wrong");
						$("#msgbox").dialog({
							modal:true,
							title:"Error",
							width:350,
							height: 200,
							show: "fade",
							hide: "fade",
							buttons: {
								OK: function() {
									$( "#msgbox" ).dialog( "close" );
								}

							},
						});
				
				}
			
			
			}


		});

	}else{
	
	$.ajax({
			url:"admin/approveuser.php?userid="+userdata+"&approve="+app,
			success:function(data){
			
			
				if(data){
					//$("msgbox").empty().html("");
					$("#msgbox").html("Sucessfully disapproved");
						$("#msgbox").dialog({
							modal:true,
							title:"",
							width:350,
							height: 200,
							show: "fade",
							hide: "fade",
							buttons: {
								OK: function() {
									$( "#msgbox" ).dialog( "close" );
									$("#userload").html(loader).load("admin/user.php");
								}

							},
						});
				}
				else{
					$("msgbox").empty().html("something went wrong");
						$("#msgbox").dialog({
							modal:true,
							title:"Error",
							width:350,
							height: 200,
							show: "fade",
							hide: "fade",
							buttons: {
								OK: function() {
									$( "#msgbox" ).dialog( "close" );
								}

							},
						});
				
				}
			
			
			}


		});
	
	
	}

}
</script>
<div id="users_list" style="overflow:auto;">
						<div>
							<label>Show:</label>
							<select name="show_no" id="show_no" >
								<option value="all">All</option>
								<option value="5">5</option>
								<option value="10">10</option>
								<option value="50">50</option>
								<option value="100">100</option>
							</select>
						<button id="disapprove">Block</button>
						<button id="approve">Unblock</button>
						
							<div id="userload">
									<?php include("user.php"); ?>
							</div>
						</div>
					</div>